package com.ophiux.micro.core.domain.page;

import java.util.List;
import java.util.Map;

public class MyPage <T> implements Page <T>  {

	private List<T> content;	//数据
	
	private int pageIndex;	//页标，从1开始
	
	private int pageSize;	//页内容大小
	
	private int pageDataCount = 0;	//数据数量,实际
	
	private Map queryPredicate;	//查询谓词,即条件
	
	private int totalPage;	//总页数
	
	private int totalCount;	//满足条件的所有数量
	
	private int isLastPage;	//是否 是最后 一页 1：是   0:不是
	
	public MyPage(int pageIndex, int pageSize , int totalCount) {
		super();
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.totalCount = totalCount;
	}
	
	/**
	 * 判断是否有内容
	 * @return  true:有   false：没有
	 */
	
	public boolean hasContent() {
		
		return (this.content == null 
				|| this.content.size() == 0) ? false : true;
		
	}
	
	/**
	 * 获取当前页标
	 * @return pageIndex
	 */
	
	public int getCurrentPageIndex() {
		return this.pageIndex;
	}
	
	/**
	 * 获取分页大小
	 * @return
	 */
	
	public int getPageSize() {
		return this.pageSize;
	}
	
	/**
	 * 获取当前页实际数量
	 * @return
	 */
	
	public int getPageDataCount() {
		return this.pageDataCount;
	}
	
	/**
	 * 判断当前页是否已满
	 * @return	true：已满   false：未满
	 */
	
	public boolean isFull() {
		return this.pageSize == this.pageDataCount ? true : false;
	}
	
	/**
	 * 设置内容
	 */
	
	public void setPageContent(List<T> content) {
		this.content = content;
		//设置实际数量
		if(this.hasContent()) {
			//有内容
			this.pageDataCount = content.size();
		}
		if((this.pageIndex - 1) * this.pageSize + this.pageDataCount >= this.totalCount){
			this.isLastPage = 1;
		}else {
			this.isLastPage = 0;
		}
	}
	
	/**
	 * 记录查询条件
	 * @param queryPredicate
	 */
	
	public void setQueryPredicate(Map queryPredicate) {
		this.queryPredicate = queryPredicate;
	}
	
	/**
	 * 获取查询谓词，查询条件
	 * @return
	 */
	
	public Map getQueryPredicate() {
		return this.queryPredicate;
	}

	
	public List<T> getPageContent() {
		return this.content;
	}

	
	public int getTotalPage() {
		return this.totalPage;
	}

	
	public int getTotalCount() {
		return this.totalCount;
	}

	
	public boolean isLastPage() {
		return this.isLastPage == 1 ? true : false;
	}
	
}
